//设置cookie
function setCookie(cName, cValue, exTime, timeIsDay = true) {
    var d = new Date();
    if (timeIsDay) {
        exTime *= 24 * 60;
    }
    d.setTime(d.getTime() + (exTime * 60 * 1000));
    var expires = "expires=" + d.toGMTString();
    if (typeof cValue == "string") {
        cValue = cValue.replace(";", "_-semicolon-_");
    }
    document.cookie = cName + "=" + cValue + "; " + expires + "; " + "path=/";
}
//获取cookie
function getCookie(cname,parse=false) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    var rst = "";
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) rst = c.substring(name.length, c.length).replace("_-semicolon-_",";");
    }
    if (parse) {
        try {
            return JSON.parse(rst);
        } catch (error) {
            return rst;
        }
    } else return rst;
}
//删除cookie
function delCookie(cName) {
    setCookie(cName, "", -1);
}
//获取所有cookie名
function allCookieNames() {
    val = document.cookie;
    val = val.split('; ');
    names = new Array();
    val.forEach(function(value,_,_) {
        names.push(value.split("=")[0]);
    });
    return names;
}
//清除所有cookie
function clearCookie() {
    allCookieNames().forEach(function (value, _, _) {
        setCookie(value, "", -1);
    });
}